const printDao = require('../dao/printDao');

const Response = require('../entity/http/Response');

const printService = {
    async createOrder(uid, { type, address, name, phone, count, file, fileName, remark }) {
        let result;
        try {
            let dbResult = await printDao.createOrder(uid, type, address, name, phone, count, file, fileName, remark);
            if (dbResult.insertId) {
                result = (new Response()).ok("创建订单成功", { id: dbResult.insertId });
            } else {
                result = (new Response()).fail(400, "创建订单失败");
            }
        } catch (err) {
            result = (new Response()).fail(500, "服务器内部错误");
        }
        return result;
    },
    async getSelfOrderList(uid) {
        let result;
        try {
            let dbResult = await printDao.getSelfOrderList(uid);
            result = (new Response()).ok("获取订单列表成功", dbResult);
        } catch (err) {
            result = (new Response()).fail(500, "服务器内部错误");
        }
        return result;
    }
};

module.exports = printService;